package cx.hoffmann.bab.dao;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import javax.persistence.PersistenceContext;

/**
 * Created by IntelliJ IDEA.
 * User: lasombra
 * Date: 2009/11/19
 * Time: 9:45:18 PM
 */

public class PersistenceInitializer
{
	@PersistenceContext
	private static EntityManagerFactory emf = null;
	private static EntityManager em = null;

	private PersistenceInitializer()
	{
	}

	public static EntityManager getEntityManager()
	{
		if( emf == null )
		{
			emf = Persistence.createEntityManagerFactory( "internalDB" );
		}

		if( em == null || !em.isOpen() )
		{
			em = emf.createEntityManager();
		}

		return em;
	}
}
